/**
Copyright [2009] [Julian Gamble] 

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

	http://www.apache.org/licenses/LICENSE-2.0 
	
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
 **/
package cruiseprojectlist.domain.coveragecomplexity;

public class Handler extends org.xml.sax.helpers.DefaultHandler {

	java.util.List<CoverageComplexity> myCoverages = new java.util.ArrayList<CoverageComplexity>();

	// private String tempVal;

	// to maintain context
	private CoverageComplexity tempCoverage;

	// Event Handlers
	public void startElement(String uri, String localName, String qName,
			org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException {
		// reset
		// tempVal = "";
		if (qName.equalsIgnoreCase("coverage")) {
			// create a new instance of employee
			tempCoverage = new CoverageComplexity();
			tempCoverage.setLinerate(attributes.getValue("line-rate"));
			tempCoverage.setBranchrate(attributes.getValue("branch-rate"));
			tempCoverage.setLinescovered(attributes.getValue("lines-covered"));
			tempCoverage.setLinesvalid(attributes.getValue("lines-valid"));
			tempCoverage.setBranchescovered(attributes
					.getValue("branches-covered"));
			tempCoverage
					.setBranchesvalid(attributes.getValue("branches-valid"));
			tempCoverage.setCcn(attributes.getValue("ccn"));
			tempCoverage.setVersion(attributes.getValue("version"));
			tempCoverage.setTimestamp(attributes.getValue("timestamp"));
		}
	}

	public java.util.List<CoverageComplexity> getCoverages() {
		// TODO Auto-generated method stub
		return myCoverages;
	}

	public void characters(char[] ch, int start, int length)
			throws org.xml.sax.SAXException {
		new String(ch, start, length);
	}

	public void endElement(String uri, String localName, String qName)
			throws org.xml.sax.SAXException {

		if (qName.equalsIgnoreCase("coverage")) {
			// add it to the list
			myCoverages.add(tempCoverage);
		}

	}
}